<html>
<head>
  <title>JSProxy example</title>
  <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
  <script src="//cdn.jsdelivr.net/sockjs/0.3.4/sockjs.min.js"></script>
  <script src="vertx-eventbus.js"></script>
  <script src="processor_service-proxy.js"></script>
</head>
<body>

<div id="result"></div>

<script>
 
  var eb = new EventBus("http://localhost:8080/eventbus");

  eb.onopen = function() {
    var processorService = new ProcessorService(eb, "vertx.processor");

    var name = getQueryVariable("document_name");
    if (name == null) {
      name = 'order';
    }

    processorService.process({name: name}, function (err, res) {
      if (err) {
        document.getElementById('result').innerHTML = 'ERROR: ' + JSON.stringify(err);
        return;
      }

      document.getElementById('result').innerHTML = 'RESULT: ' + JSON.stringify(res);
    });
  };

  function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split('&');
    for (var i = 0; i < vars.length; i++) {
      var pair = vars[i].split('=');
      if (decodeURIComponent(pair[0]) == variable) {
        return decodeURIComponent(pair[1]);
      }
    }
    console.log('Query variable %s not found', variable);
  }

</script>

</body>
</html>
